package com.yuneec.droneservice.command;

import com.yuneec.droneservice.model.ControllerSDCard;
import com.yuneec.droneservice.request.IResponse;
import com.yuneec.droneservice.utils.ByteUtils;

import java.util.Arrays;

/**
 * Created by gjw on 2017/3/27.
 */

public class GetControllerSDcard extends BaseCommand {

    public GetControllerSDcard() {
        super(MAV_RC_COMMAND.MAV_RC_CMD_GET_SDCARD_INFO);
    }

    @Override
    public IResponse<ControllerSDCard> toResponse(byte[] data, int off, int len) {
        int code = data[off + 1] & 0xff;
        IResponse<ControllerSDCard> response = new IResponse(ids(), code);
        if (code == MAV_RC_ERROR_CODE.MAV_RC_ERR_SUCCESS) {
            ControllerSDCard controllerSDCard = new ControllerSDCard();
            controllerSDCard.setInserted(data[off + 2] == 1);
            controllerSDCard.setFree(ByteUtils.byteArrayToLong(Arrays.copyOfRange(data, off + 3, off + 11), false));
            controllerSDCard.setTotal(ByteUtils.byteArrayToLong(Arrays.copyOfRange(data, off + 11, off + 19), false));
            response.setParam(controllerSDCard);
        }
        return response;
    }

}
